package edu.gatech.blackjackai.carddata;

import java.util.*;
/**
 * AIDataContainer contains all of the data that the AI uses to determine what it is to do upon each turn.
 * @author Sean Gillespie
 * @version 1.0
 */

public class AIDataContainer {
	private double money;
	private CardValue card1;
	private CardValue card2;
	private ArrayList<CardValue> hitCards;
	private int count;
	
	/**
	 * Crates a new AIDataContainer with an intial amount of money.
	 * @param money The initial amount of money
	 */
	public AIDataContainer(double money) {
		this.money = money;
		card1 = null;
		card2 = null;
		count = 0;
		hitCards = new ArrayList<CardValue>();
	}
	
	/**
	 * Attempts to give a card to the player. If the player doesn't have two cards already, then
	 * the card is given to the player and the method returns true. If the player already has two
	 * cards, then the card is added to the ArrayList of extra cards.
	 * @param card The card to be given to the player
	 * @return Whether or not the card was successfully given to the player
	 */
	public boolean cardIsGivenToPlayer(CardValue card) {
		if (card1 == null) {
			card1 = card;
			return true;
		}
		if (card2 == null) {
			card2 = card;
			return true;
		}
		else
			hitCards.add(card);
			return true;
	}
	
	/**
	 * updateCount updates the count of the deck if a certain card is added to the deck.
	 * @param card The card that was dealt
	 */
	public void updateCount(CardValue card) {
		if (card.value() > 8)
			count++;
		else if (card.value() < 5)
			count--;
	}
	
	/**
	 * cardTotal calculates the value of the cards that the AI currently has in their hand.
	 * @return The combined value of all of cards in AI's hand.
	 */
	public int cardTotal() {
		int total = card1.value() + card2.value();
		Iterator<CardValue> iterator = hitCards.iterator();
		while(iterator.hasNext()) {
			total = total + iterator.next().value();
		}
		return total;
	}
	
	/**
	 * newHand clears all of the cards out of the player's hand.
	 */
	public void newHand() {
		card1 = null;
		card2 = null;
		hitCards.clear();
	}
	
	/**
	 * Clears the current count and sets it to zero. TODO determine whether or not I need to reset the count
	 * to zero after a new deck is added back into the deck.
	 */
	public void clearCount() {
		count = 0;
	}

	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	public CardValue getCard1() {
		return card1;
	}

	public void setCard1(CardValue card1) {
		this.card1 = card1;
	}

	public CardValue getCard2() {
		return card2;
	}

	public void setCard2(CardValue card2) {
		this.card2 = card2;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
}


